Skip to content

fix: add transaction cache to L1 watcher#433

Merged
frisitano merged 2 commits intomainfrom
fix/add-tx-cache-to-l1-watcher
Nov 24, 2025
Merged

fix: add transaction cache to L1 watcher#433
frisitano merged 2 commits intomainfrom
fix/add-tx-cache-to-l1-watcher

Conversation

@frisitano
Copy link
Collaborator

@frisitano frisitano commented Nov 23, 2025

Overview

This PR addresses an issue related to the watcher. We have moved to a pattern in which we process logs in the order in which they have been produced on-chain, this is to maintain the same order when producing L1Notifications. There is an edge case in the handle_batch_commits function in which we need to know the relative position of the blob versioned hash associated with the batch commit log. This is achieved by being aware of the index of the BatchCommit log associated with the transaction. After switching to processing logs one at a time, this logic has broken. We fix this by introducing a cache, which stores the transaction and its associated blob versioned hashes. The cache exposes a method get_transaction_next_blob_versioned_hash which maintains the index of the blob versioned hash as we iterate through the logs, such that we can make this association.

Note

I have successfully synced the chain using this PR.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 23, 2025

CodSpeed Performance Report

Merging #433 will not alter performance

Comparing fix/add-tx-cache-to-l1-watcher (816bf3b) with main (81c904c)

Summary

✅ 2 untouched

Copy link
Contributor

@jonastheis jonastheis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After switching to processing logs one at a time, this logic has broken

What exactly do you mean? iiuc we still group by tx hash here:

// sort the commits by block number then batch index, then group by tx hash.

&mut self,
tx_hash: TxHash,
) -> L1WatcherResult<Option<B256>> {
if let Some(entry) = self.cache.get_mut(&tx_hash) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wonder why get_transaction_next_blob_versioned_hash also fetches it from the provider when the cache doesn't find it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because get_transaction_next_blob_versioned_hash is a stateful process, I thought it would reduce errors if we made the process more explicit and required a specific sequence.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be that there is no need to call get_transaction_next_blob_versioned_hash separately in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is possible we can remove this method in the future with a bit of refactoring.

@frisitano frisitano merged commit ff96d5f into main Nov 24, 2025
15 checks passed
@frisitano frisitano deleted the fix/add-tx-cache-to-l1-watcher branch November 24, 2025 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants